-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PEP 695] Implement new scoping rules for type parameters #17258
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great!
mypy/semanal.py
Outdated
SCOPE_CLASS: Final = 1 # Class body | ||
SCOPE_FUNC: Final = 2 # Function or lambda | ||
SCOPE_COMPREHENSION: Final = 3 # Comprehension or generator expression | ||
SCOPE_TYPE_PARAM: Final = 4 # Python 3.12 new-style type parameter scope (PEP 695) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same scoping is used for type alias values and in the future will be used for annotations (under PEP 649). In CPython we're calling this "annotation scopes", I'd suggest using the same here:
SCOPE_TYPE_PARAM: Final = 4 # Python 3.12 new-style type parameter scope (PEP 695) | |
SCOPE_ANNOTATION: Final = 4 # Annotation scopes for type parameters and aliases (PEP 695) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed as suggested.
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Type parameters get a separate scope with some special features.
Work on #15238.